import request from "@/utils/request";

//用户登录
//  /admin/acl/index/login
export const reqUserLogin = (loginParams) => {
  return request.post("/admin/acl/index/login", loginParams);
};

// 用户退出登录 /admin/acl/index/logout
export const reqUserLogout = () => {
  return request.post("/admin/acl/index/logout");
};
// 获取用户信息   /admin/acl/index/info
export const reqGetUserInfo = () => {
  return request.get("/admin/acl/index/info");
};

// 获取管理用户分页列表
// /admin/acl/user/{page}/{limit}
export const reqUserPageInfo = (page, limit, username) => {
  return request.get(`/admin/acl/user/${page}/${limit}?username=${username}`);
};

// DELETE /admin/acl/user/batchRemove
// 根据id列表删除管理用户

export const reqDeleteCheckedUser = (idList) => {
  console.log("user中的idList是", idList);
  console.log("idList的长度", idList.length);
  return request.delete("/admin/acl/user/batchRemove", idList);
};

// POST /admin/acl/user/doAssign
// 根据用户分配角色
export const reqAssignRoleByUser = (userId, roleIdList) => {
  return request.post(
    `/admin/acl/user/doAssign?userId=${userId}&roleId=${roleIdList}`
  );
};

// GET /admin/acl/user/get/{id}
// 获取管理用户

// DELETE /admin/acl/user/remove/{id}
// 删除管理用户
export const reqDeleteUser = (id) => {
  return request.delete(`/admin/acl/user/remove/${id}`);
};

// POST /admin/acl/user/save
// 新增管理用户
// PUT /admin/acl/user/update
// 修改管理用户
export const reqAddOrUpdateUser = (userInfo) => {
  if (!userInfo.id) {
    return request.post(`/admin/acl/user/save`, userInfo);
  } else {
    return request.put(`/admin/acl/user/update`, userInfo);
  }
};

// GET /admin/acl/user/toAssign/{userId}
// 根据用户获取角色数据
export const reqRoleData = (userId) => {
  return request.get(`/admin/acl/user/toAssign/${userId}`);
};
